﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Configuration;
using System.Data.SqlClient;
using System.Data;

namespace OnlineRailway.UI.Client
{
    public partial class Login1 : System.Web.UI.Page
    {
        SqlConnection con = new SqlConnection(WebConfigurationManager.ConnectionStrings["RailwayOnlineConnectionString"].ToString());
        private SqlCommand comm;
        private SqlDataReader reader;
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnLogin_Click(object sender, EventArgs e)
        {
            comm = con.CreateCommand();
            comm.CommandText = "Select * from Accounts where UserName=@user and Password=@pass";
            comm.Parameters.AddWithValue("@user", txtUsername.Text);
            comm.Parameters.AddWithValue("@pass", txtPassword.Text);
            con.Open();
            reader = comm.ExecuteReader();
            if (reader.Read())
            {
                if ((int)reader["Role"]==0)
                {
                    Response.Redirect("http://localhost:3208/UI/Administrator/Main.aspx");
                }
                else if ((int)reader["Role"] == 1)
                {
                    Response.Redirect("Home.aspx");
                }
                else
                {
                    Response.Redirect("Home.aspx");
                }
            }
        }
    }
}